function pe10(limit) {
    var sum=2+3+5+7, index=4;
    var primes = [2,3,5,7];
    
    var test = function(number) {
        var sqrt = Math.floor(Math.sqrt(number));
        for(var i=0; i<primes.length; i++) {
            if(primes[i] > sqrt) return true;
            if(number % primes[i]==0) return false;
        }
        return true;
    }
    
    for(var i=9; i<limit; i=i+2) {
        if(test(i)) {
            primes[index] = i;
            //print("Find prime " + index + "=" + i);
            index = index + 1;
            sum = sum + i;
        }
    }
    return sum;
}

print(pe10(2000000));
